package com.zy.xuanwo.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.zy.xuanwo.application.MyApplication;
import com.zy.xuanwo.zyc.portal.bean.LoginToken;

/**
 * Created by Caelan on 2016/7/16.
 */
public class UserInfoSPManager {

    public static Boolean getIsLogin() {
        SharedPreferences sharedPreferences = MyApplication.getContext().getSharedPreferences("login_token", Context.MODE_PRIVATE);
        return sharedPreferences.getBoolean("isLogin", false);
    }

    public static String getUserName() {
        SharedPreferences sharedPreferences = MyApplication.getContext().getSharedPreferences("login_token", Context.MODE_PRIVATE);
        return sharedPreferences.getString("userName", "");
    }

    public static String getPassword() {
        SharedPreferences sharedPreferences = MyApplication.getContext().getSharedPreferences("login_token", Context.MODE_PRIVATE);
        return sharedPreferences.getString("password", "");
    }

    public static void removePassword() {
        SharedPreferences sharedPreferences = MyApplication.getContext().getSharedPreferences("login_token", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.remove("password");
        editor.apply();
    }

    public static void saveUserInfo(LoginToken loginToken,String userName,String password) {
        SharedPreferences sharedPreferences = MyApplication.getContext().getSharedPreferences("login_token", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("isLogin", true);
        editor.putString("userName", userName);
        editor.putString("password", password);
        editor.putString("userId",loginToken.getUser_id());
        editor.putString("userToken",loginToken.getUser_token());
        editor.apply();

    }
    public static void removeUserInfo() {
        SharedPreferences sharedPreferences = MyApplication.getContext().getSharedPreferences("login_token", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("isLogin",false);
        editor.remove("userId");
        editor.remove("userToken");
        editor.apply();
    }

    public static String getUserToken() {
        SharedPreferences sharedPreferences = MyApplication.getContext().getSharedPreferences("login_token", Context.MODE_PRIVATE);
        return sharedPreferences.getString("userToken", "");
    }
}
